<#import "../tpl/pageTep.ftl" as page>
    <@page.pageBase currentMenu="客户管理">
   <form id="searchForm" class="form-panel" >
           <a href="${basepath}/rest/manage/customer/toList" class="backPage">返回上一级</a>
       <ul class="panel-content">
           <li>
               <div class="form-actions">
                   <div class="control-group controls span5">
                       <input type="text" class="input-normal  input-pad" name="name" placeholder="请输入关键字搜索">
                   </div>
                   <div class="form-actions  controls">
                       <button type="submit" class="button  button-primary">
                           查询
                       </button>
                       <a class="button button-primary" style="margin-left: 20px;" id="addBtn">
                           添加
                       </a>
                   </div>

               </div>
           </li>
       </ul>
   </form>
    <div id="grid"></div>
<script>
    var postData = GetRequest(),
    customerID=postData.customerID,//从客户管理列表获取取customerID
    customerName=postData.customerName;//从客户管理列表获取取customerName
    $("#searchForm").attr('action','${basepath}/rest/manage/contract/selectCustomerContractPage?customerID='+customerID+'');
    $("#addBtn").attr('href','${basepath}/rest/manage/contract/toAdd?customerID='+customerID+'&customerName='+customerName+'');
var Grid = BUI.Grid,
        Store = BUI.Data.Store,
        columns = [
            {title : '序号',elCls: 'center', dataIndex :'id', width:'10%',renderer:function (value, obj, index) {
                    return index+1;
                }},
            {title : '合同名称',elCls: 'center',dataIndex :'name', width:'15%'},
            {title : '合同编号',elCls: 'center',dataIndex :'sno', width:'15%'},
            {title : '合同金额',elCls: 'center',dataIndex :'contractMoney', width:'15%'},
            {title : '合同预付款',elCls: 'center',dataIndex :'contractPayMoney', width:'15%'},
            {title : '签订日期',elCls: 'center',dataIndex :'contractTime',width:'15%'},
            {title : '操作',elCls: 'center',dataIndex : 'id',width:'15%',renderer : function (value,obj) {
                    return '<a href="${basepath}/rest/manage/contract/toEdit?id=' + value + '&customerName='+customerName+'&customerID='+customerID+'">编辑</a>&nbsp;&nbsp;<a href="javascript:deleteOne(' +value+ ')">删除</a>&nbsp;&nbsp;<a href="/'+obj.fileUrl+'" download="">下载附件</a>';
                }
            }
        ];

var store = new Store({
            url : '/rest/manage/contract/selectCustomerContractPage',
            autoLoad:true, //自动加载数据
            params : { //配置初始请求的参数
                length : '10',
                status:$("#status").val(),
                customerID:customerID
            },
            pageSize:10,	// 配置分页数目
            root : 'list',
            totalProperty : 'total'
        }),
        grid = new Grid.Grid({
            render:'#grid',
            columns : columns,
            loadMask: true, //加载数据时显示屏蔽层
            store: store,
            plugins : [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
            // 底部工具栏
            bbar:{
                pagingBar:true
            }
        });

grid.render();
/**********************模糊搜索*************************/
var form = new BUI.Form.HForm({
    srcNode: '#searchForm'
}).render();

form.on('beforesubmit', function (ev) {
    //序列化成对象
    var obj = form.serializeToObject();
    obj.start = 0; //返回第一页
    store.load(obj);
    return false;
});
    /**********************删除单个合同信息*************************/
    function deleteOne(value) {
        BUI.Message.Confirm('确定要执行删除操作？', function () {
            $.ajax({
                type: 'POST',
                url: '${basepath}/rest/manage/contract/deleteJson',
                dataType: 'json',
                data: {
                    id: value
                },
                success: function () {
                    var obj = new Object();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }
</script>

</@page.pageBase>
